package com.itbaizhan.controller;

import com.alibaba.fastjson.JSON;
import com.itbaizhan.domain.PayInfo;
import com.itbaizhan.service.PayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author spf
 * @date 2024/4/23
 * @time 16:53
 */
@RestController
@RequestMapping("/payInfo")
public class PayInfoController {

    @Autowired
    private PayInfoService payInfoService;

    @GetMapping("/pay_account")
    public String pay(@RequestParam("account_no") String account_no, @RequestParam("amount") BigDecimal amount){
        payInfoService.save(account_no, amount);
        return "充值成功";
    }

    @GetMapping("/query")
    public String query(@RequestParam("txNo") String txNo){
        PayInfo payInfoByTxNo = payInfoService.getPayInfoByTxNo(txNo);
        return JSON.toJSONString(payInfoByTxNo);
    }

}
